/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.structure.composite.transparent;

import java.util.ArrayList;
import java.util.List;

/**
 * 树枝构件
 *
 * @author lizhixing
 */
public class Composite implements Component {
  private List<Component> children = new ArrayList<>();

  @Override
  public void add(Component c) {
    children.add(c);
  }

  @Override
  public void remove(Component c) {
    children.remove(c);
  }

  @Override
  public Component getChild(int i) {
    return children.get(i);
  }

  @Override
  public void operation() {
    for (Component obj : children) {
      obj.operation();
    }
  }
}
